package com.plat.api.api.action;

import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSONObject;
import com.plat.api.anonation.Token;
import com.plat.api.dao.api.PlatVideoDao;
import com.plat.api.entity.api.PlatVideoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: shish
 * Date: 2020/9/1
 * Time: 22:37
 * Description: 搜索页面
 */
@Service
@Token
public class SearchAction {
    @Autowired
    private PlatVideoDao platVideoDao;
    /**
     * 初始化搜索页面
     */
    public JSONObject initSearchIndex(JSONObject jsonObject) {
        //1、加载推荐搜索词条：推荐才显示
        //2、加载推荐作者点播视频、直播：推荐才显示
        //3、加载头条信息：推荐才显示
        //4、加载通知类：推荐才显示
       List<PlatVideoEntity> list =   platVideoDao.createLambdaQuery().andEq("is_recommend",1).orderBy("RAND()").page(1, RandomUtil.randomInt(1,10)).getList();
       JSONObject json = new JSONObject();
//        List<Obj> list = new ArrayList<>();
//        Obj obj_1 = new Obj();
//        obj_1.setBgColor("black");
//        obj_1.setUrl("/pages/XXX");
//        obj_1.setLabel("张三");
//        list.add(obj_1);
//        Obj obj_2 = new Obj();
//        obj_2.setBgColor("red");
//        obj_1.setUrl("/pages/XXX");
//        obj_2.setLabel("张四");
//        list.add(obj_2);
//        Obj obj_3 = new Obj();
//        obj_3.setBgColor("blue");
//        obj_1.setUrl("/pages/XXX");
//        obj_3.setLabel("张武");
//        list.add(obj_3);
        json.put("list",list);
        return json;
    }
    private class Obj{
        private String url;
        private String bgColor;
        private String label;

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public String getBgColor() {
            return bgColor;
        }

        public void setBgColor(String bgColor) {
            this.bgColor = bgColor;
        }

        public String getLabel() {
            return label;
        }

        public void setLabel(String label) {
            this.label = label;
        }
    }
}
